using System.Windows.Forms;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Controls;
using DevExpress.XtraGrid.Views.Base;
using NAGFwk.UI.Properties;

namespace NAGFwk.UI
{
    public class GridHelper
    {
        public static void GridViewFocusObject(ColumnView cView, object obj)
        {
            if (obj == null) return;
            int oldFocusedRowHandle = cView.FocusedRowHandle;
            for (int i = 0; i < cView.DataRowCount; ++i)
            {
                object rowObj = cView.GetRow(i) as object;
                if (rowObj == null) continue;
                if (ReferenceEquals(obj, rowObj))
                {
                    if (i == oldFocusedRowHandle)
                        cView.FocusedRowHandle = GridControl.InvalidRowHandle;
                    cView.FocusedRowHandle = i;
                    break;
                }
            }
        }
        public static void SetFindControlImages(GridControl grid)
        {
            FindControl fControl = null;
            foreach (Control ctrl in grid.Controls)
            {
                fControl = ctrl as FindControl;
                if (fControl != null) break;
            }
            if (fControl != null)
            {
                fControl.FindButton.Image = Resources.Search;
                fControl.ClearButton.Image = Resources.Delete_16x16;
                fControl.CalcButtonsBestFit();
            }
        }
    }
}
